<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.ArrayList" %>
<%@ page  import ="es.ats.codington.festival.domain.People" %>
<%@ page  import ="es.ats.codington.festival.domain.Visitor" %>

<html>
	

	
<head>
	<title>Home Visitor</title>
    <link rel='stylesheet' href='./css/estilos.css'>
	<link rel="shortcut icon" href="./images/5CS.jpg">
	
</head>
<body>

        <%
			String userName = "";
        	String message = "";
			Cookie[] cookies = request.getCookies();
			if(cookies !=null){
				for(Cookie cookie : cookies){
    				if(cookie.getName().equals("visitor")) userName = cookie.getValue();
    				if(cookie.getName().equals("message")) message = cookie.getValue();
				}
			}
			if(userName == null) response.sendRedirect("login.jsp");
	 	%>

<div id="contenedor">
	<div id="cabecera">
	<h1>New Codington</h1>
	</div>
	</div>

<% 
int aux = (Integer) session.getAttribute("Session"); 


if (aux==1){
%>	<div class="alert alert-success">
	<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
	<strong>Done!</strong> The visitor has been deleted!!
</div><%

}
else if (aux==2){
	%>	<div class="alert alert-danger">
	<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
	<strong>Fail!</strong> The visitor can't be deleted!!
</div><%
	
}
session.setAttribute("Session", -1);
%>
	
	<div class="menufinal" align="center">
	   	<table>
	<thead>

    	<tr>
		      <th><form action="create_place.jsp">
		<input type='submit' class="btn btn-lg btn-primary" value="Create new place"></input>
	</form></th>
	  <th><form action="CreateEventServlet">
		<input type='submit' class="btn btn-lg btn-primary" value="Create new event"></input>
	</form></th>
	<th><form action="ListAllEventServlet">
		<input type='submit' class="btn btn-lg btn-primary" value="View all events"></input>
	</form></th>
	<th><form action="ListAllVisitorsServlets">
		<input type='submit' class="btn btn-lg btn-primary" value="View all visitor"></input>
	</form></th>
	 <th><form action="UpdateVisitorServlet">
		<input type='submit' class="btn btn-lg btn-primary" value="Modify my profile"></input>
	</form></th>
	 <th><form action="UpdateVisitorPassServlet">
		<input type='submit' class="btn btn-lg btn-primary" value="Modify my password"></input>
	</form></th>
	 <th><form action="LogoutServlet" method="GET">
		<input type='submit' class="btn btn-lg btn-primary" value="Sing out"></input>
	</form></th>
    </tr>
  </thead>
	</table>

</div>	
	
	<style type="text/css">
	 body {
			background: url(images/imagen.jpeg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
	}
    </style>
    
    
	<div align="center">
		<form class="contacto"  action="ListAllVisitorsServlet" method="post" align="center" >
			<table>
  				<thead>
    				<tr>
    					<th colspan="14">Visitor's list</th></tr>
    				<tr>
      					<th colspan="2" align="center">Username</th>
	  					<th colspan="2" align="center">Name</th>
	  					<th colspan="2" align="center">LastName</th>
      					<th colspan="2" align="center">Age</th>
      					<th colspan="2" align="center">Address</th>
	  					<th colspan="2" align="center">Phone Number</th>
	  					<th colspan="2" align="center">Options</th>
    				</tr>
  				</thead>
  				<tbody>
  					<% 	ArrayList<Visitor> visitors = new ArrayList<Visitor>();  
  						visitors = ((ArrayList<Visitor>)session.getAttribute("AllVisitors"));  
  						for(int i =0; i<visitors.size(); i++){
	 				 %>    
	  			<tr>
      				<td><%=visitors.get(i).getUsername() %><td>
      				<td><%=visitors.get(i).getName() %><td>
      				<td><%=visitors.get(i).getLastName() %><td>
      				<td><%=visitors.get(i).getAge() %><td>
      				<td><%=visitors.get(i).getAddress() %><td>
      				<td><%=visitors.get(i).getPhoneNumber() %><td>
      				<td>
      					<form action="DeleteVisitorServlet" method="POST">
        					<button class="btn btn-lg btn-primary" type="submit" name="visitorID" value=<%=visitors.get(i).getVisitorId()%>>Delete</button>
        				</form>
      				</td>
       				<%  }
  					%>
    			</tr>
				</tbody>
			</table>				
		</form>
	</div>
</body>
</html>
    